package test;

import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
import edu.ntnu.superrss.models.SyndFeedImpl;
import edu.ntnu.superrss.utils.HibernateUtil;
import edu.ntnu.superrss.utils.feedgrabber.UrlQueue;
import edu.ntnu.superrss.utils.feedgrabber.UrlWorker;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.hibernate.Session;



public class Main {

	public static void main(String[] args) throws MalformedURLException, IllegalArgumentException, FeedException, IOException {
		// eksempel på å legge noe i kø
		UrlQueue urlQueue = UrlQueue.getInstance();
		urlQueue.add(new URL("http://www.vg.no/rss/create.php?categories=34,20,39,32&keywords=&limit=10"));
		
		//Eksempel på å hente en spesifikk feed
		//SyndFeed feed = UrlWorker.grabFeed(new URL("http://freeantilope.org/feed/rss/"));

		//RESTERENDE eksempler bør generaliseres og puttes i DAO
		//--
		
		//Eksempel på enkel lagring/oppdatering av feed
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		//session.merge(feed);
                session.getTransaction().commit();
		session.getSessionFactory().close();

		//eksempel på å hente en liste fra DB
		List liste = session.createQuery("from SyndFeedImpl").list();
	}
	
}
